<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function buttonOnclick() {
            alert("静态onclick事件")
        }

        window.onload = function () {
            //获取标签对象
            var btn001 = document.getElementById("btn001");
            //标签对象.事件名 = funciton(){}
            btn001.onclick = function () {
                alert("动态onclick事件");
            }
        }
    </script>
</head>
<body>
    <button onclick="buttonOnclick()">按钮1</button>
    <button id="btn001">按钮2</button>
</body>
</html>